<?php
if(isset($_POST['guid']))
	{
		require("includes/basic.php");
		//$taskid=$_POST['gtid'];
		$pid=$_POST['pid'];
		$sid=$_POST['sid'];
		$mid=$_POST['mid'];
		$rid=$_POST['guid'];
		$uid=$_POST['guid'];	
	$d=$_POST['gtid'];
	$id= split(',',$d);
	foreach($id as $a => $b)
	{
		$assigntask=mysql_query("insert into task_assigned_to (`task_id`,`task_assigned_to`,`task_assigned_on`,`task_assigned_by`,`project_id`,`phase_id`,`module_id`,`role_id`) values ('$b','$rid',sysdate(),'$userId','$pid','$sid','$mid','4')");
		}
	}
	if(isset($_POST['s']))
	{
		require("includes/basic.php");
		$s=$_POST['s'];
		
		$pid=$_POST['pid'];
		$sid=$_POST['sid'];
		$mid=$_POST['mid'];
		$sql="select * from task_master where project_id=$pid and phase_id=$sid and module_id=$mid and LOWER(task_title) like LOWER('$s%')";
	}
else
{
$pid=$_REQUEST['pid'];
$sid=$_REQUEST['sid'];
$mid=$_REQUEST['mid'];
 
$sql="select * from task_master where project_id=$pid and phase_id=$sid and module_id=$mid";
}
include('ps_pagination.php');
$pager = new PS_Pagination($conn, $sql, 8, 5, "param1=valu1&param2=value2");
	
	/*
	 * Enable debugging if you want o view query errors
	*/
	$pager->setDebug(true);
	
	/*
	 * The paginate() function returns a mysql result set
	 * or false if no rows are returned by the query
	*/
	$rs = $pager->paginate();
	if(!$rs) die(mysql_error());


	$sr=1;
$class="evenrowbg";
?>

<form id='viewtasks' name='viewtasks' action='' method='post'>

<table width='100%' cellpadding='1' cellspacing='0' class='list'>
	<tr>
		<th  style='white-space: nowrap;'>
			<div style='display:block;'>
				<span class="link linkdisabled">T</span>
			</div>
		</th>
		<th style='white-space: nowrap;'>
			<div style='display:block; '>
				<span class="link linkdisabled">Open</span>
			</div>
		</th>
		
		<th style='white-space: nowrap;'>
			<div style='display:block; '>
				<span class="link">Task Title</span>
			</div>
		</th>
		<th style='white-space: nowrap;'>
			<div style='display:block; '>
				<span class="link">Task Description</span>
			</div>
		</th>
		<th style='white-space: nowrap;' align='center'>
			<span class="link">Resource name</span>
		</th>
		<th style='white-space: nowrap;' align='center'>
			<span class="link">Task Assigned By</span>
		</th>
		<th style='white-space: nowrap;'>
			<span class="link">Priority</span>
		</th>
		<th style='white-space: nowrap;'>
			<span class="link">Time Alloted</span>
		</th>
		<th style='white-space: nowrap;'>
			<span class="link">Status</span>
		</th>
		<th style='white-space: nowrap;'>
			<span class="link">Edit Status</span>
		</th>
		
		<th width='0' class='select'>
			<input type='checkbox' class='checkbox' id='listSelectAll' name='listSelectAll'>
		</th>
	</tr>
	
	<?php
	
	while($taskr=mysql_fetch_array($rs))
	{
		$taskid=$taskr['task_id'];
		$title=$taskr['task_title'];
		$taskdesc=substr($taskr['task_description'],0, 50)."..";
		$priority=$taskr['task_priority'];
		$time_alloted=$taskr['estimated_time']." hrs";
		$prostatus=$taskr['record_status'];
		$getresource=mysql_query("select * from user_master u, task_assigned_to t where t.task_id=$taskid and t.task_assigned_to=u.user_id and project_id=$pid and phase_id=$sid and module_id=$mid");
		$getstatus=mysql_query("select * from task_status td, status_type st where td.task_id=$taskid and td.task_status=st.status_id");
		$statusr=mysql_fetch_array($getstatus);
		extract($statusr);
		
		if($class=="evenrowbg")
		{
			$class="oddrowbg";
		}
		else
		{
			$class="evenrowbg";
		}
		echo "<tr class='$class'>";
		?>
		<td  style='white-space: nowrap; text-align:center;'>
			<a href=<?php echo "edit-task.php?t=$taskid"; ?> ><img src='images/edit.png' alt='Edit' title='Edit'></a>
		</td>
		<td style='white-space: nowrap; text-align:center;'><a href="task-details.php?t=<?php echo $taskid; ?>"><img src='images/open-project.png' alt='Show Details' Title='Show Details'></a>
		</td>
		<td style='white-space: nowrap;'>
				<?php echo $title;?>
		</td>
		<td style='white-space: nowrap;'>
				<?php echo $taskdesc;?>
		</td>
		<td style='white-space: nowrap;' style='text-align:center;'>
			<?php 
			
				while($res=mysql_fetch_array($getresource))
				{
				echo $res['first_name']." ".$res['last_name']."<br/>";
				}
			
			?>
		</td>
		<td style='white-space: nowrap;' style='text-align:center;'>
			<?php 
		 $assignby="select * from task_assigned_to as t, customer_master as c where t.task_assigned_by=c.customer_id and t.task_id=".$taskid;
		$assignby_res=mysql_query($assignby);
		if(mysql_num_rows($assignby_res)>0)
		{
			while($rw1=mysql_fetch_array($assignby_res))
			{
			//extract($rw1);		
			//assignby=$rw1['cust_fname'];
			echo $rw1['customer']."<br/>";
			
			}
		}
		else { 
		
		$assignby1=mysql_query("select * from task_assigned_to as t, user_master as u where t.task_assigned_by=u.user_id and t.task_id=".$taskid);
		while($r=mysql_fetch_array($assignby1))
			{
		echo $r['first_name']." ".$r['last_name']."<br/>";
			}
		}
		?>
		</td>
		<td style='white-space: nowrap;'>
			<?php echo $priority;?>
		</td>
		<td style='white-space: nowrap;'>
			<?php echo $time_alloted;?>
		</td>
		<td style='white-space: nowrap;'>
			<span class="link"><?php echo $status;?></span>
		</td>
		<td style='white-space: nowrap; text-align:center;'>
			<a href=<?php echo "edit-status.php?t=$taskid"; ?> ><img src='images/edit.png' alt='Edit' title='Edit status'></a>
		</td>
		<td width='0' class='select' style='text-align:center;'>
			<input type='checkbox' class='checkbox' value="<?php echo $taskid; ?>" id='taskid' name='taskid'>
		</td>

		<?php
		echo "</tr>";
		
	}
	
	?>
</table>
</form>

<?php

	//Display the full navigation in one go
	 echo "<br />\n";?>
	<span style="text-align:justify; margin-left:320px;"><?php  echo $pager->renderFullNav(); ?> </span>